package sedh.project

import grails.test.*

class AlocadorMunProgIntTests extends GroovyTestCase {
	
	def alocMunProg1, alocMunProg2
	
    protected void setUp() {
        super.setUp()
    }

    protected void tearDown() {
        super.tearDown()
    }

    void testCriaESalvaAlocacoes() {
		
		def p1 = new Programa(nome: "Programa1", descricao: "Descricao1").save()
		def m1 = new Municipio(nome : "municipio3", habitantes: 100000).save()
		
		def p2 = new Programa(nome: "Programa2", descricao: "Descricao2").save()
		def m2 = new Municipio(nome : "municipio4", habitantes: 1000000).save()
		
		alocMunProg1 = new AlocadorMunProg(municipio: m1, programa: p1, telefone: 35412213, responsavel: "Responsavel1", familias: 100)
		alocMunProg2 = new AlocadorMunProg(municipio: m2, programa: p2, telefone: 35411090, responsavel: "Responsavel2", familias: 100)
		
		alocMunProg1.save()
		alocMunProg2.save()
		
		assertNotNull(alocMunProg1)
		assertNotNull(alocMunProg2)
		
		assertEquals 2, AlocadorMunProg.count()
    }
	
	void testDeletaTodosOsAlocados() {
		def all = AlocadorMunProg.getAll()
		
		for (AlocadorMunProg aloc : all) {
			aloc.delete(flush : true)
		}
		
		assertEquals 0, AlocadorMunProg.count()
	}
	
}
